/*****************************************************************************
 *
 *              Main.c -- user main program
 *
 *****************************************************************************
 * FileName:        HardwareProfile.c
 
 *****************************************************************************/
#include "SystemProfile.h"
#include "Compiler.h"
#include "WirelessProtocols\Console.h"
#include "TimeDelay.h"
#include "HardwareProfile.h"




   _FOSCSEL(FNOSC_PRI);                                    //primary osc
   _FOSC(OSCIOFNC_OFF & POSCMD_HS);                           // XT Osc
 ///  _FWDT(FWDTEN_OFF & WDTPOST_PS2)                        // Disable Watchdog timer
//   // JTAG should be disabled as well

    _FWDT(FWDTEN_OFF & WDTPOST_PS16384 & WDTPRE_PR128 & WINDIS_OFF); // reset em 2 minutos e 11 segundos


#define DEBOUNCE_TIME 0x00003FFF

BOOL PUSH_BUTTON_pressed;
MIWI_TICK PUSH_BUTTON_press_time;



/*********************************************************************
 * Function:        void BoardInit( void )
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    Board is initialized for P2P usage
 *
 * Overview:        This function configures the board 
 *
 * Note:            This routine needs to be called before the function 
 *                  to initialize P2P stack or any other function that
 *                  operates on the stack
 ********************************************************************/

void BoardInit(void)
{
   
   TRISBbits.TRISB12 = 0;
   LATBbits.LATB12 = 0;               
  
        // set I/O ports
        LED_1_TRIS = 0;
        LED_2_TRIS = 0;
        

        PHY_CS_TRIS = 0;
        PHY_CS = 1;
        PHY_RESETn_TRIS = 0;
        PHY_RESETn = 1;
   
        RF_INT_TRIS = 1;
        
        SDI_TRIS = 1;
        SDO_TRIS = 0;
        SCK_TRIS = 0;
        SPI_SDO = 0;        
        SPI_SCK = 0;             
            
        PHY_WAKE_TRIS = 0;
        PHY_WAKE = 1;
                   
        #if defined(HARDWARE_SPI)
            SPI1CON1 = 0b0000000100111110;
            SPI1STAT = 0x8000;
 
            SPI2CON1 = 0b0000000100111110;
            SPI2STAT = 0x8000;
        #endif
      
        INTCON2bits.INT1EP = 1;
                     
        #if defined(ENABLE_NVM)

            EE_nCS_TRIS = 0;
            EE_nCS = 1;
        
        #endif

        RFIF = 0;
   
        
        if( RF_INT_PIN == 0 )
        {
            RFIF = 1;
        }
    

   
}


